//获取当天日期
function getDate(fromDate) {

	var char = "-";
	var date = fromDate ? fromDate : new Date();
	var day = date.getDate();
	var month = date.getMonth() + 1;//注意月份需要+1
	var year = date.getFullYear();
	//补全0，并拼接
	return year + char + (month < 10 ? "0" + month : month) + char + (day < 10 ? "0" + day : day);

};

function generateUUID() {
  let d = new Date().getTime();
  if (window && window.performance && typeof window.performance.now === "function") {
      d += performance.now(); //use high-precision timer if available
  }
  let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
      let r = (d + Math.random() * 16) % 16 | 0;
      d = Math.floor(d / 16);
      return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
  });
  return uuid;
}

function getQueryString(name) {
  let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  let r = window.location.search.substr(1).match(reg); //search,查询？后面的参数，并匹配正则
  if (r != null) return unescape(r[2]);
  return null;
}

export default { getDate, generateUUID, getQueryString };